package day01;




public class MyThread {
    public static void main(String[] args) throws InterruptedException {
        Object aA = new Object();
        Object bB = new Object();
        Object cC = new Object();
        MThread A =new MThread("A",cC,aA);
        MThread B =new MThread("B",aA,bB);
        MThread C =new MThread("C",bB,cC);
        Thread AA = new Thread(A);
        Thread BB = new Thread(B);
        Thread CC = new Thread(C);
        AA.start();
        Thread.sleep(100);
        BB.start();
        Thread.sleep(100);
        CC.start();

    }
}
class MThread implements Runnable{
    private String name;
    private Object prev;
    private Object self;

    public MThread( String name,Object prev, Object self) {
        this.prev = prev;
        this.name = name;
        this.self = self;
    }

    @Override
    public void run() {
        int count = 10;
        while(count>0){
        synchronized (prev){
                synchronized (self){
                    System.out.print(name);
                    System.out.print(count);
                    count--;
                    self.notify();

                }
                }

            }
        }
    }
